package org.andao.core.base.controller;

import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.Date;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.propertyeditors.CustomBooleanEditor;
import org.springframework.beans.propertyeditors.CustomNumberEditor;
import org.springframework.web.bind.WebDataBinder;
import org.springframework.web.bind.annotation.InitBinder;
import org.springframework.web.servlet.DispatcherServlet;

/**
 * 继承Spring MVC {@link DispatcherServlet}的控制器抽象基类.<p>
 * 提供绑定自定义对象支持.
 * @author Seewo software - Marco.hu(huzhiguo@cvte.cn)
 */
public  class BinderSupportController extends DispatcherServlet{
	
	private static final long serialVersionUID = 3590817951907508588L;

	protected Logger logger = LoggerFactory.getLogger(getClass());
		
	/**
	 * 注册常用的对象类型.
	 * @param binder
	 */
	@InitBinder
    public void initBinder(WebDataBinder binder) {	
        binder.registerCustomEditor(Date.class, new CustomDateEditor(true));
        binder.registerCustomEditor(Boolean.class, new CustomBooleanEditor(true));
		binder.registerCustomEditor(Integer.class, null,new CustomNumberEditor(Integer.class, null, true));
		binder.registerCustomEditor(Long.class, null, new CustomNumberEditor(Long.class, null, true));
		binder.registerCustomEditor(Float.class, new CustomNumberEditor(Float.class, true));
		binder.registerCustomEditor(Double.class, new CustomNumberEditor(Double.class, true));
		binder.registerCustomEditor(BigInteger.class, new CustomNumberEditor(BigInteger.class, true));
		binder.registerCustomEditor(BigDecimal.class, new CustomNumberEditor(BigDecimal.class, false));
		logger.debug("start init custom editor binder...");
		initCustomEditorBinder(binder);
    }
	
	/**
	 * 初始化自定义的数类型.
	 * @param binder
	 */
	public  void initCustomEditorBinder(WebDataBinder binder){
		//TODO
	}
	
	
}
